﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BMSQ.Utility;

namespace BMSQ.Admin.Accounts.User
{
    public partial class Add : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txtUserName.Text.Trim().Length == 0)
            {
                strErr += "用户名不能为空！\\n";
            }
            if (this.txtUserPwd.Text.Trim().Length == 0)
            {
                strErr += "密码不能为空！\\n";
            }
            if (this.txtTrueName.Text.Trim().Length == 0)
            {
                strErr += "真实姓名不能为空！\\n";
            }

            if (PageValidate.IsPhone(this.txtPhone.Text.Trim()))
            {
                strErr += "手机格式不正确！\\n";
            }
            if (!PageValidate.IsEmail(this.txtEmail.Text.Trim()))
            {
                strErr += "Email格式不正确！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string UserName = this.txtUserName.Text;
            string UserPwd = this.txtUserPwd.Text;
            string TrueName = this.txtTrueName.Text;
            string Sex = ddlSex.SelectedValue;
            string Phone = this.txtPhone.Text;
            string Email = this.txtEmail.Text;
            int UserType = 1;

            Vincent.Permission.Model.account_userlist model = new Vincent.Permission.Model.account_userlist();
            model.UserID =DBParameter.GetGuid();
            model.UserName = UserName;
            model.UserPwd = UserPwd;
            model.TrueName = TrueName;
            model.Sex = Sex;
            model.Phone = Phone;
            model.Email = Email;
            model.UserType = UserType;

            Vincent.Permission.Functions.Account.AddUser(model);
            MessageBox.ShowAndRedirect(this, "保存成功！", "add.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}